package jcu.mobile.library.namespace;

import android.os.Bundle;
import android.app.Activity;
import java.util.ArrayList;  
import android.content.Intent;
import android.view.View;  
import android.widget.AdapterView;  
import android.widget.GridView;  
import android.widget.AdapterView.OnItemClickListener;  

public class HomeActivity extends Activity {

    private GridViewAdapter mAdapter;  
    private ArrayList<String> gridviewLabel;  
    private ArrayList<Integer> gridviewImage;  
  
    private GridView gridView;  
  
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        
        
        prepareList();  
        
        // prepared arraylist and passed it to the Adapter class  
        mAdapter = new GridViewAdapter(this,gridviewLabel, gridviewImage);  
  
        
        // Set custom adapter to gridview  
        gridView = (GridView) findViewById(R.id.gridView1);  
        gridView.setAdapter(mAdapter);  
  
        

        // Switch Intent by Item Selection on GridView ("position starts from '0'")  
        gridView.setOnItemClickListener(new OnItemClickListener()
        {
        	public void onItemClick(AdapterView<?> arg0, View v, int position, long id)
        	{
        		Intent myIntent = null;
        		
        		//Call SearchBook Intent
        		if (position == 0)
        		{
                    myIntent = new Intent(HomeActivity.this, SearchBookActivity.class);
                    
        		}
        		
        		//Call NewArrival Intent
        		else if (position == 1)
        		{
        			myIntent = new Intent(HomeActivity.this, NewArrivalActivity.class);
        		}
        		
        		
        		//Call NewsAnnounce Intent
        		else if (position == 2)
        		{
        			myIntent = new Intent(HomeActivity.this, NewsAnnounceActivity.class);
        		}
        		
        		
        		//Call AddNews Intent
        		else if (position == 3)
        		{
                    myIntent = new Intent(HomeActivity.this, AddNewsActivity.class);
                    

        		}

        		
        		//execute the intent statement above
        		startActivity(myIntent);

        	}
        });
  
    }  
    



  
    public void prepareList()  
    {  
          gridviewLabel = new ArrayList<String>();  
  
          //add labels into gridview items
          gridviewLabel.add("Search");  
          gridviewLabel.add("New Arrivals");  
          gridviewLabel.add("News");  
          gridviewLabel.add("Wish List");  
          gridviewLabel.add("Room Booking");  
          gridviewLabel.add("My Account");  
          gridviewLabel.add("Contact Us");  
          gridviewLabel.add("Opening Hour");  
          gridviewLabel.add("About Us");  

  
          //add images into gridview items
          gridviewImage = new ArrayList<Integer>();  
          gridviewImage.add(R.drawable.search);  
          gridviewImage.add(R.drawable.newsss);  
          gridviewImage.add(R.drawable.news);  
          gridviewImage.add(R.drawable.wishlist);  
          gridviewImage.add(R.drawable.booking);  
          gridviewImage.add(R.drawable.myaccount);  
          gridviewImage.add(R.drawable.contactus);  
          gridviewImage.add(R.drawable.clock);  
          gridviewImage.add(R.drawable.about_us);  
          
    }  

}  